package com.groupseven.backend.services.impl;

import com.groupseven.backend.domain.Paper.Paper;
import com.groupseven.backend.mapper.PaperMapper;
import com.groupseven.backend.services.PaperService;
import com.groupseven.backend.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class PaperServiceImpl implements PaperService {
    @Autowired
    private PaperMapper paperMapper;
    @Autowired
    private UserService userService;
    /**
     * @Author 王志华
     * @return
     */
    public List<Paper> getAllPapersInfo(){
        return paperMapper.selectAllPapers();
    }

    /**
     * @Author 王志华
     * @param paper
     * @return
     */
    public int insertPaperInfo(Paper paper){
        if(paperMapper.selectByPaperNumber(paper.PaperNumber)!=null){
            return 0;
        }
        return paperMapper.insertPaperInfo(paper);
    }

    /**
     * @Author 王志华
     * @param paper
     * @return
     */
    public int isPaperExits(Paper paper) {
        if (paperMapper.selectByPaperNumber(paper.PaperNumber)==null){
            return 0;
        }
        return 1;
    }

    public List<Paper> selectByPaperusername(String username){
        return paperMapper.selectByPaperusername(username);
    }

    public Paper selectByPaperNumber(String PaperNumber) {
        return paperMapper.selectByPaperNumber(PaperNumber);
    }

    public List<Paper> selectByPaperName(String PaperName){
        return paperMapper.selectByPaperName(PaperName);
    }

    public int updatePaper(Paper paper){
        if(paperMapper.selectByPaperNumber(paper.PaperNumber)==null){
            return 0;
        }
//        else if(userService.selectByUsername(paper.username)==null){
//            return -1;
//        }
        else {
            return paperMapper.updatePaper(paper);
        }
//        return paperMapper.updatePaper(paper);
    }

    public int deleteByPaperNumber(String PaperNumber){
        if (paperMapper.selectByPaperNumber(PaperNumber)==null){
            return 0;
        }
        else {
            return paperMapper.deleteByPaperNumber(PaperNumber);
        }
    }

    public int deleteallPapers(){
        return paperMapper.deleteallPapers();
    }

    //////////////////////////////////////////////
    public int mutildelPapers(List<String> PaperNumbers){
        return paperMapper.mutildelPapers(PaperNumbers);
    }

    public List<Paper> getlikeByPaperName(String PaperName){
        return paperMapper.getlikeByPaperName(PaperName);
    }

    public List<Paper> getlikeMyPaperInfo(String username){
        return paperMapper.getlikeMyPaperInfo(username);
    }

    public List<Paper> getlikeByPaperNumber(String PaperNumber){
        return paperMapper.getlikeByPaperNumber(PaperNumber);
    }

    public List<Paper> getlikeByAllAuthors(String AllAuthors){
        return paperMapper.getlikeByAllAuthors(AllAuthors);
    }
/////////////////////////////////////////////

    /////////////////////////////////
    public List<Paper> searchqueryPaper(String query){
        query = "%" + query + "%";
        return paperMapper.searchqueryPaper(query);
    }
    ///////////////////////////////
    //////////////////////////////////////////
    public List<Paper> searchuserqueryPaper (String query,String username){
        return paperMapper.searchuserqueryPaper(query,username);
    }
    //////////////////////////////////////
}
